package com.mlk.good.controller;

import cn.hutool.core.util.IdUtil;
import com.mlk.core.component.LayEditAdapt;
import com.mlk.core.component.page.Page;
import com.mlk.core.component.page.Pager;
import com.mlk.core.util.ServerResponse;
import com.mlk.good.po.EngGood;
import com.mlk.good.po.EngGoodInfo;
import com.mlk.good.po.EngGoodIntroduce;
import com.mlk.good.po.EngGoodPic;
import com.mlk.good.service.EngGoodService;
import com.mlk.good.vo.EngGoodVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.jws.WebParam;


/**
 * 商品controller
 */
@Controller
@RequestMapping("/eng/good")
public class EngGoodController {

    @Resource
    private EngGoodService engGoodService;

    /**
     * 返回首页
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "good/good";
    }

    /**
     * 商品列表
     * @param good
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public Pager list(EngGood good){
        return this.engGoodService.list(good);
    }

    /**
     * 返回商品新增页面
     * @return
     */
    @RequestMapping("addPage")
    public String addPage(Model model){
        // 生成一个oreder的id
        Long id = IdUtil.createSnowflake(2, 2).nextId();
        model.addAttribute("id",id);
        return "good/addPage";
    }

    /**
     * 商品新增
     */
    @RequestMapping("add")
    @ResponseBody
    public ServerResponse add(@RequestBody EngGoodVO goodVO){
        return this.engGoodService.add(goodVO);
    }

    /**
     * 上传商品介绍的富文本内容
     * @return
     */
    @ResponseBody
    @RequestMapping("uploadIntroducePic")
    public LayEditAdapt uploadIntroducePic(MultipartFile file){
        return this.engGoodService.uploadIntroducePic(file);
    }

    /**
     * 上传文件内容
     * @param pic
     * @return
     */
    @RequestMapping("uploadGoodPic")
    @ResponseBody
    public ServerResponse uploadGoodPic(EngGoodPic pic,MultipartFile file){
        return this.engGoodService.uploadGoodPic(pic,file);
    }

    /**
     * 删除图片信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("delGoodPic")
    public ServerResponse delGoodPic(Integer id){
        return this.engGoodService.delGoodPic(id);
    }

    /**
     * 商品上下架
     * @return
     */
    @RequestMapping("goodChangeStatus")
    @ResponseBody
    public ServerResponse goodChangeStatus(String id ){
        return this.engGoodService.goodChangeStatus(id);
    }


    /**
     * 修改商品的主体信息
     * @return
     */
    @ResponseBody
    @RequestMapping("update")
    public ServerResponse updateGoodInfo(EngGood good){
        return this.engGoodService.updateGoodInfo(good);
    }

    /**
     * 获取商品描述信息
     * @return
     */
    @ResponseBody
    @RequestMapping("getIntroduce")
    public ServerResponse getIntroduce(String id){
        return this.engGoodService.getIntroduce(id);
    }

    /**
     * 修改商品描述信息
     * @return
     */
    @ResponseBody
    @RequestMapping("updateIntroduce")
    public ServerResponse updateIntroduce(EngGoodIntroduce introduce){
        return this.engGoodService.updateIntroduce(introduce);
    }

    /**
     * 获取商品图片信息
     * @return
     */
    @ResponseBody
    @RequestMapping("getGoodPic")
    public ServerResponse getGoodPic(String id){
        return this.engGoodService.getGoodPic(id);
    }

    /**
     * 查询商品子项列表
     * @param goodId
     * @return
     */
    @RequestMapping("goodParamList")
    @ResponseBody
    public Pager goodParamList(String goodId){
        return this.engGoodService.goodParamList(goodId);
    }

    /**
     * 增加商品子项
     * @return
     */
    @ResponseBody
    @RequestMapping("addGoodParamItem")
    public ServerResponse addGoodParamItem(EngGoodInfo info){
        return  this.engGoodService.addGoodParamItem(info);
    }

    /**
     * 修改商品子项
     * @return
     */
    @ResponseBody
    @RequestMapping("updateParamItem")
    public ServerResponse updateParamItem(EngGoodInfo info){
        return this.engGoodService.updateParamItem(info);
    }

    /**
     * 规格上下架
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("changeParamItem")
    public ServerResponse changeParamItem(Integer id){
        return this.engGoodService.changeParamItem(id);
    }
}
